define(function(require) {
	var $ = require("jquery");
	var justep = require("$UI/system/lib/justep");

	var Model = function() {
		this.callParent();
		this.url = null;
		this.outTradeNo = null;
	};

	Model.prototype.modelParamsReceive = function(event) {
		this.url = event.data.data.url;
		this.outTradeNo = event.data.data.orderNo;
		this.compObj = event.data.data.compObj;
		this.comp('codeData').setValue('url', this.url);
	};

	Model.prototype.pageClose = function() {
		this.close();
	}

	Model.prototype.sureBtnClick = function(event) {
		var self = this;
		$.ajax({
			type: "GET",
			url: require.toUrl("/wxapi/mp/pay/queryOrder"),
			dataType: 'json',
			async: false,
			cache: false,
			data: {
				"outTradeNo": this.outTradeNo,
			},
			success: function(res) {
				if (res.success && res.data != undefined && res.data.resultCode == "SUCCESS") {
					if (res.data.tradeState != "SUCCESS") {
						justep.Util.hint(res.data.tradeStateDesc, {
							"type": "danger"
						});
						self.compObj._onPayFail();
					} else {
						self.close();
						justep.Util.hint("支付成功", {
							"type": "success"
						});
						self.compObj._onPaySuccess(res);
					}
				} else {
					justep.Util.hint(res.msg, {
						"type": "danger"
					});
					self.compObj._onPayFail();
				}
			},
			error: function(res) {
				justep.Util.hint(res.msg, {
					"type": "danger"
				});
			}
		});
	};

	return Model;
});